package com.ifreeee.practice;

import com.ifreeee.practice.aop.proxy.TestAopProxy;
import com.ifreeee.practice.bean.A;
import com.ifreeee.practice.cfg.AppConfig;
import com.ifreeee.practice.proxy.Base;
import com.ifreeee.practice.proxy.IBase;
import com.ifreeee.practice.proxy.ProxyInvocationHandler;
import com.ifreeee.practice.service.IndexServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.lang.reflect.Proxy;

public class Practice {

    public static void main(String[] args) {
        //testAop();
        base();
        //cont();
        //jdkProxy();
        //testMybatis();
        //testLog();
    }

    public static void base() {
        AnnotationConfigApplicationContext ac =
                new AnnotationConfigApplicationContext(AppConfig.class);

        A a = ac.getBean("a", A.class);
        System.out.println(a.getB());
        System.out.println(a.getB());
    }
    //public static void cont() {
    //    AnnotationConfigApplicationContext ac =
    //            new AnnotationConfigApplicationContext();
    //    ac.getEnvironment().setActiveProfiles("production");
    //    ac.register(AppConfig.class);
    //    ac.refresh();
    //    A a = ac.getBean("a", A.class);
    //    System.out.println(a);
    //    if (a == null) {
    //        return;
    //    }
    //    System.out.println(a.getB());
    //    System.out.println(a.getB());
    //    System.out.println(a.getB());
    //
    //    System.out.println(a.getB().getA());
    //    System.out.println(a.getB().getA());
    //    System.out.println(a.getB().getA());

    //}
    //public static void jdkProxy() {
    //    IBase base = (IBase) Proxy.newProxyInstance(Practice.class.getClassLoader()
    //            , new Class[]{IBase.class}, new ProxyInvocationHandler(new Base()));
    //    base.query();

    //}
    //public static void testMybatis() {
    //    AnnotationConfigApplicationContext ac =
    //            new AnnotationConfigApplicationContext(AppConfig.class);
    //    IndexServiceImpl indexServiceImpl = ac.getBean("indexServiceImpl", IndexServiceImpl.class);
    //    System.out.println(indexServiceImpl.select());

    //}
    //public static void testLog () {
    //    Log log = LogFactory.getLog("");
    //    log.info("spring-jcl-over-slf4j");

    //}
    public static void testAop() {
        AnnotationConfigApplicationContext ac =
                new AnnotationConfigApplicationContext(AppConfig.class);

        TestAopProxy a = ac.getBean("aop", TestAopProxy.class);
        a.eat();

    }
}
